import React, { useState } from "react";
import PubSub from 'pubsub-js'

export default function Search() {
  let [keyword, setKeyword] = useState('');// 这里空字符串一定要设置
  //搜索的点击事件
  let search = () => {
    //发布消息
    PubSub.publish('keyword', keyword);
  }
  return (
    <div className="row">
      <div className="col-lg-3 col-lg-offset-9">
        <div className="input-group">
          <input
            type="text"
            className="form-control"
            placeholder="关键字"
            value={keyword}
            onChange={(e) => {
              setKeyword(e.target.value);
            }}
          />
          <span className="input-group-btn">
            <button onClick={search} className="btn btn-default" type="button">
              搜索
            </button>
          </span>
        </div>
      </div>
    </div>
  );
}
